package com.ssps.back.platform.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssps.back.platform.service.CommissionService;
import com.ssps.entity.Commission;
import com.ssps.utils.MyLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author li
 * @time 2020/07/23 16:38:49
 */

@Controller
@RequestMapping("commission")
public class CommissionController {

    @Autowired
    CommissionService commissionService;

    @RequestMapping("commissionList")
    public  String commissionList(){
        return "/commission/commissionList";
    }


    /*
    *信息展示
    * */
    @MyLog
    @ResponseBody
    @RequestMapping("findAll")
    public Map<String,Object> commissionFindAll(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize){

        Map<String,Object> map=new HashMap<>();
        try {
            PageHelper.startPage(pageNum,pageSize);
            List<Commission> commissionList=commissionService.commissionFindAll();
            PageInfo<Commission>pageInfo=new PageInfo<>(commissionList);
            map.put("pageInfo",pageInfo);
            map.put("commissionList",commissionList);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",true);
            e.printStackTrace();
        }
        return map;
    }


    /*
     *信息新增
     * */
    @MyLog
    @ResponseBody
    @RequestMapping("commissionSave")
    public Map<String,Object> commissionSave(Commission commission){

        Map<String,Object> map=new HashMap<>();
        try {
            commissionService.commissionSave(commission);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",true);
            e.printStackTrace();
        }
        return map;
    }


    /*
     *启用或禁用
     * */
    @MyLog
    @ResponseBody
    @RequestMapping("updateAudit")
    public Map<String,Object>commissionUpdate(Commission commission){
        Map<String,Object> map=new HashMap<>();

        try {
            commissionService.commissionUpdate(commission);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",false);
            e.printStackTrace();
        }

        return map;
    }

}
